package com.zwps.biz.domain.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zwps.biz.api.enums.ProTypeEnum;
import com.zwps.biz.api.model.vo.pubpointall.PubPointCountVO;
import com.zwps.biz.api.model.vo.strsvrr.*;
import com.zwps.biz.dal.db.dao.PubPointAllDAO;
import com.zwps.biz.dal.db.dao.ZEmergencyUserDAO;
import com.zwps.biz.dal.db.object.ZEmergencyUserDO;
import com.zwps.biz.domain.service.ZEmergencyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author：yxm
 * @Package：com.zwps.biz.domain.service.impl
 * @Project：cqsk_manager
 * @name：ZEmergencyUserServiceImpl
 * @Date：2025/4/18 下午5:42
 * @Filename：ZEmergencyUserServiceImpl
 */
@DS("one")
@Service
public class ZEmergencyUserServiceImpl extends ServiceImpl<ZEmergencyUserDAO, ZEmergencyUserDO> implements ZEmergencyUserService {

    @Autowired
    private ZEmergencyUserDAO zEmergencyUserDAO;
    @Autowired
    PubPointAllDAO pubPointAllDAO;

    @Override
    public List<EmergencyUserVO> getEmergencyUser(String type, String keyword) {
        List<ZEmergencyUserDO> zEmergencyUserDOS = zEmergencyUserDAO.selectList(Wrappers.lambdaQuery(ZEmergencyUserDO.class).eq(ZEmergencyUserDO::getType, type)
                .like(StringUtils.isNotBlank(keyword), ZEmergencyUserDO::getName, keyword).eq(ZEmergencyUserDO::getIsDelete, 0));
        return zEmergencyUserDOS.stream().map(e -> {
            EmergencyUserVO emergencyUserVO = new EmergencyUserVO();
            emergencyUserVO.setName(e.getName());
            emergencyUserVO.setPhone(e.getPhone());
            emergencyUserVO.setDuty(e.getDuty());
            emergencyUserVO.setId(e.getId().toString());
            emergencyUserVO.setWorkPosition(e.getWorkPosition());
            return emergencyUserVO;
        }).collect(Collectors.toList());
    }
    public List<DischargeCapacityVO> getDischargeCapacityDateByeOPening(String opening) {

        return zEmergencyUserDAO.getDischargeCapacityDateByeOPening(opening);
    }

    public List<DischargeCapacityVO> getSandflushin( ) {

        return zEmergencyUserDAO.getSandflushin();
    }


    @Override
    public List<DischargeCapacityVO> getCoupledLeakage() {
        return zEmergencyUserDAO.getCoupledLeakage();
    }

    @Override
    public List<RzWRelationVO> getRzW() {
        return zEmergencyUserDAO.getRzW();
    }

    @Override
    public PubPointCountVO getWaterLawEnforcementCounts(Integer year) {
        return zEmergencyUserDAO.getWaterLawEnforcementCounts(year);
    }

    @Override
    public List<PubCommonFileVO> getFileByType(Integer type) {
        return zEmergencyUserDAO.getFileByType( type);
    }

    @Override
    public DsmPtrRecordCountVO getpatrolDate(String year, Integer type,Integer mounth) {
        String finalType = null;
        if (type != null) {
            finalType = ProTypeEnum.getByCode(type);
        }
        DsmPtrRecordCountVO recordCountVO = zEmergencyUserDAO.getCount(year, finalType,mounth);
        List<DsmPtrRecordVO> dsmPtrRecordVOS = zEmergencyUserDAO.getpatrolDate(year, finalType,mounth);


        recordCountVO.setList(dsmPtrRecordVOS);
        return recordCountVO;
    }

    @Override
    public PatrolCountVO countPatrolByYear(String year) {
        PatrolCountVO pubPointCountVO = pubPointAllDAO.countPatrolByYear(year);
        if (ObjectUtils.isEmpty(pubPointCountVO)) {
            pubPointCountVO = new PatrolCountVO();
        }
        return pubPointCountVO;
    }

    @Override
    public List<String> getpatrolDataYear() {
        return pubPointAllDAO.getpatrolDataYear();
    }

    @Override
    public List<PtrRecordDetailVO> getpatrolList(String id) {
        return pubPointAllDAO.getpatrolList(id);
    }
}